import * as React from "react"
import { type Metadata } from "next"
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { getTemplateList } from "@/lib/email-template/service"
import { type SearchParams } from "@/types/table"
import { SearchParamsEmailTemplateCache } from "@/lib/email-template/validations"
import { TemplateTable } from "@/lib/email-template/table/email-template-table"
import { Shell } from "@/components/shell"
import { getValidFilters } from "@/lib/data-table"
import { Skeleton } from "@/components/ui/skeleton"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { useTranslation } from "@/i18n"

export const metadata: Metadata = {
  title: "템플릿 관리",
  description: "이메일 템플릿을 관리하고 편집합니다.",
}

interface TemplatePageProps {
  params: Promise<{ lng: string }>
  searchParams: Promise<SearchParams>
}

export default async function TemplatePage(props: TemplatePageProps) {
  const { lng } = await props.params
  const { t } = await useTranslation(lng, 'menu')

  const searchParams = await props.searchParams

  const search = SearchParamsEmailTemplateCache.parse(searchParams)
  const validFilters = getValidFilters(search.filters)


  const promises = Promise.all([
    getTemplateList({
      ...search,
      filters: validFilters,
    }),

  ])

  return (

    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.information_system.email_template')}
              </h2>
              {/* <InformationButton pagePath="evcp/equip-class" /> */}
            </div>
          </div>
        </div>
      </div>

      <React.Suspense fallback={<Skeleton className="h-7 w-52" />}>
      </React.Suspense>
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={6}
            searchableColumnCount={1}
            filterableColumnCount={2}
            cellWidths={["10rem", "40rem", "12rem", "12rem", "8rem", "8rem"]}
            shrinkZero
          />
        }
      >
        <TemplateTable promises={promises} />
      </React.Suspense>
    </Shell>
  )
}
